package com.freewater.library;

import com.freewater.library.common.infrastructure.event.DomainEventDispatcher;
import com.freewater.library.common.infrastructure.event.SyncDomainEventDispatcher;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
@EnableJpaRepositories(basePackages = {
        "com.freewater.library.catalogue.infrastructure.dao",
        "com.freewater.library.lending.book.infrastructure.dao",
        "com.freewater.library.lending.reader.infrastructure.dao",
})
@EntityScan(basePackages = {
        "com.freewater.library.catalogue.infrastructure.po",
        "com.freewater.library.lending.book.infrastructure.po",
        "com.freewater.library.lending.reader.infrastructure.po",
        "com.freewater.library.lending.dailysheet.model",
        "com.freewater.library.lending.reservedsheet.model",
        "com.freewater.library.lending.checkedoutsheet.model",
})
public class LibraryLearnApplication {

    @Bean
    public DomainEventDispatcher domainEventDispatcher(ApplicationEventPublisher eventPublisher) {
        return new SyncDomainEventDispatcher(eventPublisher);
    }

    public static void main(String[] args) {
        SpringApplication.run(LibraryLearnApplication.class, args);
    }

}
